﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

namespace ZHDJ.MobileInterface.html
{
    public partial class PartyForumDital : System.Web.UI.Page
    {
        public string ForumID
        {
            get
            {
                return Request.QueryString["ForumID"] ?? "";
            }
        } 

        public string ForumTitle
        {
            get;
            set;
        }

        public string ForumCreateBy
        {
            get;
            set;
        }

        public string CreateTime
        {
            get;
            set;
        }

        public string ForumContent
        {
            get;
            set;
        }

        public string ImagUrl
        {
            get;
            set;
        }

        public string CurrentPageStr
        {
            get;
            set;
        }

        public string TotalPageStr
        {
            get;
            set;
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                DataSet dsForum = InterfaceHelper.GetPartyForumDetailInfo(ForumID);

                if (dsForum != null && dsForum.Tables[0].Rows.Count > 0)
                {
                    ForumTitle = "[" + dsForum.Tables[0].Rows[0]["Title"].ToString() + "]" + dsForum.Tables[0].Rows[0]["ForumTitle"];
                    ForumCreateBy = dsForum.Tables[0].Rows[0]["UserName"].ToString();
                    CreateTime = dsForum.Tables[0].Rows[0]["CreateTime"].ToString();
                    ForumContent = dsForum.Tables[0].Rows[0]["ForumContent"].ToString();

                    ForumContent = ForumContent.Replace("src=\"/fs/UploadFiles/Party", "src=\"http://www.ith71.cn/fs/UploadFiles/Party");
                    ForumContent = ForumContent.Replace("src=\"/fs/UploadFiles/party", "src=\"http://www.ith71.cn/fs/UploadFiles/party");
                    //ForumContent = ForumContent.Replace("<p>   &nbsp;</p>", ""); 

                    //ImagUrl = CommonUtils.GetSmallImg(SXT.Utility.FileServer.QueryFileUrl(dsForum.Tables[0].Rows[0]["ImageUrl"].ToString()));
                    ImagUrl = CommonUtils.GetFileUrl(dsForum.Tables[0].Rows[0]["ImageUrl"].ToString());
                    if (string.IsNullOrEmpty(ImagUrl) || ImagUrl == "#")
                        ImagUrl = "../../Resource/Themes/Default/Images/Widget/BBS_noavatar_medium.gif";
                }
                else
                {
                    return;
                }


                DataSet dsReply = InterfaceHelper.GetPartyForumReplyInfo(ForumID);
                if (dsReply != null && dsReply.Tables[0].Rows.Count > 0)
                {
                    for(int i = 0; i < dsReply.Tables[0].Rows.Count; i++)
                    {
                        dsReply.Tables[0].Rows[i]["RowNumber"] = (i + 1).ToString();
                        //dr["ImageUrl"] = SXT.Utility.FileServer.QueryFileUrl(dr["ImageUrl"].ToString());
                        dsReply.Tables[0].Rows[i]["ImageUrl"] = CommonUtils.GetFileUrl(dsReply.Tables[0].Rows[i]["ImageUrl"].ToString());
                        dsReply.Tables[0].Rows[i]["ReplyContent"] = dsReply.Tables[0].Rows[i]["ReplyContent"].ToString().Replace("src=\"/fs/UploadFiles/party", "src=\"http://www.ith71.cn/fs/UploadFiles/party");

                        if (string.IsNullOrEmpty(dsReply.Tables[0].Rows[i]["ImageUrl"].ToString()) || dsReply.Tables[0].Rows[i]["ImageUrl"].ToString() == "#")
                            dsReply.Tables[0].Rows[i]["ImageUrl"] = "../../Resource/Themes/Default/Images/Widget/BBS_noavatar_medium.gif";
                    } 
                }

                PagedDataSource Pgds = new PagedDataSource();
                Pgds.DataSource = dsReply.Tables[0].DefaultView;
                Pgds.AllowPaging = true;
                Pgds.PageSize = 10;
                TotalPageStr = Pgds.PageCount.ToString();
                int CurrentPage;
                try
                {

                    CurrentPage = Convert.ToInt32(Request.QueryString["Page"]); 
                } 
                catch
                { 
                    CurrentPage = 1;
                }
                 
                if (CurrentPage > Pgds.PageCount)
                    CurrentPage = Pgds.PageCount;

                if (CurrentPage < 1)
                    CurrentPage = 1;


                Pgds.CurrentPageIndex = CurrentPage - 1;
                CurrentPageStr = CurrentPage.ToString();
                //if (!Pgds.IsFirstPage)
                //{
                //    lnkPrev.NavigateUrl = Request.CurrentExecutionFilePath + "?ForumID=" + ForumID + "&Page=" + Convert.ToString(CurrentPage - 1);
                //}
                //if (!Pgds.IsLastPage)
                //{
                //    lnkNext.NavigateUrl = Request.CurrentExecutionFilePath + "?ForumID=" + ForumID + "&Page=" + Convert.ToString(CurrentPage + 1);
                //}
                //lnkFirst.NavigateUrl = Request.CurrentExecutionFilePath + "?ForumID=" + ForumID + "&Page=1";
                //lnkLast.NavigateUrl = Request.CurrentExecutionFilePath + "?ForumID=" + ForumID + "&Page=" + TotalPageStr;

                rptComment.DataSource = Pgds;
                rptComment.DataBind();

                InterfaceHelper.UpdatePartyForumVisitTimes(ForumID);
            }
        }
    }
}